package fileread;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import util.io.file.JDirectBufFileReader;
import util.io.file.JFileReader;


public class FileReadTestMain {

    /**
     * @param args
     */
    public static void main(String[] args) {
        
        String path = args[0]; 

        //String path = "D:\\DATA_JAPAN\\mines_ha_20090727.3001.3202.3";
        
        
        //readFile(path);
        
        readFile2(path);
        
        
    }
    
    

   static public void readFile(String path){
       
       byte[] _fdata = null;
       String data = null;
       
       try {
           JFileReader fd = new JDirectBufFileReader(path, true, 1024*16);
           
           while(!fd.isEOF()) {
               try {
                   
                   _fdata = fd.readLine();                 // 파일에서 한 라인을 읽어들인다.
                   if (_fdata == null ) 
                       break;
                   
                   System.out.println(_fdata.length);             //  파일에서 log를 읽었다.
                   
                   data = new String(_fdata).trim();
                   
                   System.out.println(data);

               } catch (Exception e) {
                   System.out.println(e.getMessage());
               }
           }
           
       } catch (FileNotFoundException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }
       System.out.println("============================================================");
   }
   
   
   
   static public void readFile2(String path){
       String s;
       
       Pattern p = Pattern.compile("†"); 

       
       try {
        BufferedReader in = new BufferedReader(
                new InputStreamReader(
                        new FileInputStream(
                                new File(path)
                                ) , "SJIS" //, "Shift_JIS"//, "Shift-JIS" //, "SJIS" 
                        ) 
                );
        
        while ((s = in.readLine()) != null) {     //파일의 내용이 있으면 출력

        System.out.println(s);
        
        Matcher m = p.matcher(s);
        int count = 0;
        for( int i = 0; m.find(i); i = m.end())
        count++;

        System.out.println("특정문자열(Pattern)의 갯수 : " + count); //특정문자열(Pattern)의 갯수
        
        }
        
        in.close();
        
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

   }
   
   
}
